<!--  -->
<template>
  <div>
    <div>
      <el-table class="table1" v-if="tableData.tableData" :data="tableData.tableData" border>
        <el-table-column v-for="(cel,ind) in headerData" :key="ind" align="center"
                         :label="cel.label" width="200px" size="medium">
          <template slot-scope="scope">
            <div v-if="scope.column.label === '考察项目'">
              <span>{{scope.row[cel.prop].inspect_project_name}}</span>

            </div>
            <div v-else-if="scope.column.label === '全检用量'">
              <template v-if="scope.row.name.inspect_project_name == '样品量'">
                {{totalTo(cel.prop)}}
              </template>
              <template v-else>
                <span>
                  {{scope.row[cel.prop].packaging_nu}}
                  {{scope.row[cel.prop].packaging_nu_unit !== '' ? scope.row[cel.prop].packaging_nu_unit :scope.row[cel.prop].packaging_unit}}
                </span>

              </template>

            </div>
          </template>
          <template v-if="cel.children.length > 0">
            <el-table-column v-for="col in cel.children" :key="col.label + col.unit" align="center">
              <template #header>
                {{col.label}}{{col.unit}}
              </template>
              <template slot-scope="scope">
                <template v-if="scope.row.name.inspect_project_name == '样品量'">
                  {{totalTo(col.prop,cel.label)}}
                </template>
                <template v-else>
                  <span v-if="scope.row[col.prop]">√</span>
                  <span v-else>/</span>
                  <!-- <el-checkbox v-model="scope.row[col.prop]" @change="hanldChange" disabled>
                  </el-checkbox> -->
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table-column>
      </el-table>

      <div class="zong">
        <div class="left">
          总计
        </div>
        <div class="rigth" v-if="totalof.length>0">
          <el-form style="display:flex;justify-content: flex-start;align-items:center">
            <el-form-item label="单倍量" v-for="(dex,ind) in totalof" :key="ind + 'xx'"
                          class="form-item">
              <el-input v-model="dex.value" placeholder="单倍量" disabled></el-input>
              <div v-if="dex.arrList.length > 1" style="flex-shrink:0;padding-left:5px">
                <span style="padding:0 5px">*</span>
                {{dex.arrList.length}}
              </div>
              <span v-if="ind < totalof.length - 1" style="padding-left:25px ">+</span>
            </el-form-item>
            <el-form-item class="form-item">
              = {{sumNum()}} {{totalof[0].unit || ''}}
            </el-form-item>

          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { downListProject, pointList } from '@/api/stability/giveUp'

  export default {
    props: {
      tableHead: {
        type: Array,
        default: function() {
          return []
        }
      },
      tableList: {
        type: Object,
        default: function() {
          return {
            stability_sample_info: {
              sample_type_info: {
                inspect_projects: []
              }
            }
          }
        }
      },
      tableData: {
        type: Object,
        default: function() {
          return {
            tableData: [],
            combined: {},
            total: {}
          }
        }
      },stability: {
        type: Number,
        default: function() {
          return 0
        }
      }

    },
    data() {
      return {
        headerData: [
          {
            label: '考察项目',
            prop: 'name',
            children: []
          },
          {
            label: '全检用量',
            prop: 'num',
            children: []
          }
        ],
        index: undefined,
        ind: undefined,
        num: undefined,
        title: '',
        numIndex: 0,
        arr: {},
        dataList: [],
        projectData: [],
        openBoole: undefined,
        list: [],
        aaa: {
          boole: true,
          name: { inspect_project_name: '样品量' },
          num: {}
        },
        totalof: [],
        ssss: {}
      }
    },
    //是计算属性，也可以理解为一个方法。
    computed: {},
    //属性是手动定义的所需监听的值
    watch: {},
    //生命周期 - 创建完成（访问当前this实例）
    created() {
      this.handlDown()
    },
    //生命周期 - 挂载完成（访问DOM元素）
    mounted() {
      this.headerData = this.headerData.concat(this.hanldTable(this.tableHead))
      this.hanldList()
      this.handlTotal()
      this.handlSort()
      this.handlHead()
    },
    //是Vue实例对象上绑定的方法，供当前Vue组件作用域内使用，
    methods: {
      //处理样品量
      totalTo: function(prop, label) {
        this.hanldChange()
        let a, b
        if (prop === 'num') {
          let num1 = 0,
            un_unit1 = '',
            unit1 = '',
            num_nuit1 = undefined,
            total1 = 0

          for (let i = 0; i < this.tableData.tableData.length; i++) {
            if (this.tableData.tableData[i].num.packaging_nu !== undefined) {
              num1 += this.tableData.tableData[i].num.packaging_nu || 0
              un_unit1 = this.tableData.tableData[0].num.packaging_nu_unit || ''
              unit1 = this.tableData.tableData[0].num.packaging_unit || ''
              num_nuit1 = this.tableData.tableData[0].num.num_nuit
              if (num_nuit1 === 0 && un_unit1 === '') {
                a = `${num1} ${unit1}`
              } else {
                total1 = Math.ceil(num1 / num_nuit1) || 0
                a = `${num1} ${un_unit1} / ${total1} ${unit1}`
              }
            }
          }
          if (!this.tableData.combined.num) {
            this.tableData.combined.num = a
          }
          if (this.stability == 2) {
            console.log(654465)
            return this.tableData.combined.num
          } else {
            this.tableData.combined.num = a
            return a
          }
        } else {
          let num = 0,
            un_unit = '',
            unit = '',
            num_nuit = undefined,
            total = 0
          let asd = 0
          for (let i = 0; i < this.tableData.tableData.length; i++) {
            if (this.tableData.tableData[i][prop]) {
              asd++
              num += this.tableData.tableData[i].num.packaging_nu || 0
            }
            un_unit = this.tableData.tableData[0].num.packaging_nu_unit || ''
            unit = this.tableData.tableData[0].num.packaging_unit || ''
            num_nuit = this.tableData.tableData[0].num.num_nuit
            let ssa = asd ? 1 : 0
            total = Math.ceil(num / num_nuit) || ssa
            if (num_nuit === 0 && un_unit === '') {
              b = `${num} ${unit}`
            } else {
              b = `${num} ${un_unit} / ${total} ${unit}`
            }
          }
          if (!this.tableData.combined[prop]) {
            this.tableData.combined[prop] = b
          }
          if (!this.ssss[label]) {
            this.ssss[label] = []
          }
          if (total == Infinity) {
            total = num
          }
          let data = {
            val: total,
            prop: prop,
            unit: unit
          }
          let index = this.ssss[label].findIndex(a => a.prop == prop)
          if (index != -1) {
            this.ssss[label][index] = data
          } else {
            this.ssss[label].push(data)
          }
          if (this.stability == 2) {
            let cc
            if (this.tableData.combined[prop]) {
              cc = this.tableData.combined[prop]
            } else {
              cc = `1 ${un_unit} /1 ${unit}`
            }
            return cc
          } else {
            this.tableData.combined[prop] = b
            return b
          }
        }

      },

      //求和
      sumNum() {
        let num = 0
        for (let i = 0; i < this.totalof.length; i++) {
          num += this.totalof[i].value * this.totalof[i].arrList.length
        }
        return num
      },

      //获取项目下拉
      handlDown() {
        downListProject().then(res => {
          if (res.code === 200) {
            this.projectData = res.data || []
          }
        })
      },

      //项目下拉
      handlChange(val, index, vvv) {
        let aa = '',
          bb = ''
        let ind = this.projectData.findIndex(a => a.id === val)
        if (ind !== -1) {
          aa = this.projectData[ind].id
          bb = this.projectData[ind].inspect_project_name
        }
        let indx = this.tableData.tableData.findIndex(
          a => a.name.id === aa && a.name.inspect_project_name === bb
        )
        if (indx !== -1) {
          this.$message.error('考察项目已存在列表')
          this.tableData.tableData[index].name.id = vvv
        } else {
          this.tableData.tableData[index].name.id = aa
          this.tableData.tableData[index].name.inspect_project_name = bb
        }
      },

      //全检用量事件
      handlInputNum(val, index) {
        //this.tableData.tableData[index].num.packaging_nu = val;
      },

      handlBlurInput() {
        this.columnB = ''
      },

      //处理表头
      hanldTable(arrData) {
        this.tableData.headList = []
        let aaa = [],
          data = {}
        for (let i = 0; i < arrData.length; i++) {
          if (!data[arrData[i].place_conditions.place_conditions_type.id]) {
            data[arrData[i].place_conditions.place_conditions_type.id] = [
              arrData[i]
            ]
          } else {
            data[arrData[i].place_conditions.place_conditions_type.id].push(
              arrData[i]
            )
          }
        }
        for (let key in data) {
          let str = '',
            ids = ''
          for (let j = 0; j < data[key].length; j++) {
            let dataVal = data[key][j]
            str += data[key][j].place_conditions.place_conditions_name
            ids +=
              data[key][j].place_conditions.place_conditions_type.id + '&?' +
              data[key][j].place_conditions.id
            if (j == data[key].length - 1) {
              let children = []
              for (let k = 0; k < dataVal.sample_point.sample_point_info.length; k++) {
                let infoData = dataVal.sample_point.sample_point_info[k]
                let val = {
                  label: infoData.sample_point_num,
                  unit: infoData.sample_point_unit === 1 ? '天' : '月',
                  prop:
                    dataVal.place_conditions.place_conditions_type
                      .place_conditions_type_name +
                    '' +
                    '-' +
                    infoData.sample_point_num +
                    '-' +
                    infoData.sample_point_unit,
                  num: infoData.sample_point_unit,
                  ids: ids,
                  children: []
                }
                children.push(val)
              }
              this.tableData.headList.push(dataVal.place_conditions.place_conditions_type
                .place_conditions_type_name)
              children = [...new Set(children)]
              aaa.push({
                label: str,
                ids: ids,
                prop:
                  data[key][0].place_conditions.place_conditions_type
                    .place_conditions_type_name + '',
                id: key,
                children: children
              })
            } else {
              str = str + '、'
              ids = ids + '、'
            }
          }
        }
        aaa = [...new Set(aaa)]
        return aaa
      },

      //总计input
      handlTotal() {
        let list = []
        if (this.tableData.total.a !== undefined) {
          for (let h = 0; h < this.tableData.total.a.length; h++) {
            this.tableData.total.a[h].sample = this.tableList
            this.tableData.total.a[h].arrList.forEach(item => {
              item.sample = this.tableList
            })
          }
          list = this.tableData.total.a
        } else {
          this.totalof = []
        }
        for (let i = 0; i < this.headerData.length; i++) {
          if (this.headerData[i].children.length > 0) {
            let value = 0
            let obj = null
            let arrList = []
            let labelArr = this.headerData[i].label.split('、')
            let idArr = this.headerData[i].ids.split('、')
            let aa = list.findIndex(a => a.ids === this.headerData[i].ids)
            if (aa !== -1) {
              arrList = list[aa].arrList
              value = list[aa].value
            } else {
              for (let j = 0; j < labelArr.length; j++) {
                obj = {
                  name: labelArr[j],
                  id: idArr[j],
                  sample: this.tableList,
                  value: 0,
                  sample_info: this.tableList,// 样品信息
                  inspection_type_id: this.tableData.ides,//考察类型
                  place_conditions_id: idArr[j].split('&?')[1],//放置条件id
                  place_conditions_type_id: idArr[j].split('&?')[0],//放置条件类型id
                  num: ''// 单倍量
                }
                arrList.push(obj)
              }
            }
            this.totalof.push({
              [this.headerData[i].ids]: this.headerData[i].ids.split('、'),
              value: value,
              unit: '',
              arrList: arrList,
              label: this.headerData[i].label,
              ids: this.headerData[i].ids,
              sample: this.tableList
            })
          }
        }
        this.tableData.total = { a: this.totalof }
      },

      //总计输入框
      handlInput(val) {
        for (let i = 0; i < this.tableData.total.a.length; i++) {
          let aaa = this.tableData.total.a[i]
          if (aaa.value === val) {
            aaa.value = Number(val)
            aaa.arrList.forEach(item => {
              item.value = Number(val)
            })
          }
        }
      },

      //
      confirmTelephone(val) {
        let reg = /^\+?[1-9][0-9]*$/
        if (!reg.test(val.target.value)) {
          val.target.value = ''
        }
      },

      //处理表的prop数据
      hanldList() {
        let arr = [],
          a = {},
          b = {},
          c = '',
          data = {}
        for (let i = 0; i < this.headerData.length; i++) {
          data[this.headerData[i].prop] = ''
          if (this.headerData[i].children.length > 0) {
            for (let j = 0; j < this.headerData[i].children.length; j++) {
              data[this.headerData[i].children[j].prop] = false
            }
          }
        }
        let inspect_projects = this.tableList.sample_type_info.inspect_projects
        for (let k = 0; k < inspect_projects.length; k++) {
          a = {
            id: inspect_projects[k].id,
            inspect_project_name: inspect_projects[k].inspect_project_name
          }
          b = {
            packaging_nu: this.tableList.packaging_nu,
            num_nuit: this.tableList.packaging_nu,
            packaging_nu_unit: this.tableList.packaging_nu_unit,
            packaging_unit: this.tableList.packaging_unit
          }
          c = this.tableList.sample_type_info.same_type_id
          data.name = a
          data.num = b
          data.boole = true
          arr.push({ ...data })
        }
        this.obj = { ...arr[0] }
        if (this.tableData.tableData.length === 0) {
          this.tableData.tableData = arr
          this.tableData.id = c
          this.tableData.tableData.push(this.aaa)
        } else {
          if (c !== this.tableData.id) {
            let bbb = [...this.tableData.tableData]
            for (let i = 0; i < arr.length; i++) {
              let data = arr[i]
              if (data.name && data.name.id) {
                let index = bbb.findIndex(a => a.name && a.name.id === data.name.id)
                if (index !== -1) {
                  for (let key in data) {
                    if (bbb[index][key] && key !== 'num') {
                      data[key] = bbb[index][key]
                    }
                  }
                }
              }
            }
            this.tableData.tableData = arr
            this.tableData.id = c
            this.tableData.tableData.push(this.aaa)
          }

        }
        this.tableData.tableData.forEach((item, index) => {
          if (index === this.tableData.tableData.length - 1) {
            item.num = {
              packaging_nu: 0,
              num_nuit: 0,
              packaging_nu_unit: this.tableList.packaging_nu_unit,
              packaging_unit: this.tableList.packaging_unit
            }
          } else {
            item.num.num_nuit = b.num_nuit
            item.num.packaging_nu_unit = b.packaging_nu_unit
            item.num.packaging_unit = b.packaging_unit
          }
        })
      },

      //勾选事件
      hanldChange(val) {
        setTimeout(_ => {
          if (this.stability == 2) return
          for (let j = 0; j < this.totalof.length; j++) {
            this.totalof[j].value = 0
            if (this.ssss[this.totalof[j].label]) {
              for (let k = 0; k < this.ssss[this.totalof[j].label].length; k++) {
                this.totalof[j].value += Number(
                  this.ssss[this.totalof[j].label][k].val
                )
                this.totalof[j].unit = this.ssss[this.totalof[j].label][k].unit
                for (let i = 0; i < this.totalof[j].arrList.length; i++) {
                  this.totalof[j].arrList[i].value = this.totalof[j].value
                }
              }
              this.tableData.total = { a: this.totalof }
            }
          }
        }, 100)
      },

      //添加项目
      addTable() {
        this.openBoole = 2
        this.open = true
        this.title = '选择项目'
      },

      handleAddTable() {
        let data = JSON.parse(JSON.stringify(this.obj))
        let name = ''
        let id = ''
        //data = this.tableData.tableData[0]
        let index = this.projectData.findIndex(a => a.id == this.formOpen.id)
        if (index !== -1) {
          name = this.projectData[index].inspect_project_name
          id = this.projectData[index].id
        }
        data.name.id = id
        data.name.inspect_project_name = name
        this.tableData.tableData.splice(
          this.tableData.tableData.length - 1,
          0,
          data
        )
      },

      //单机行
      aloneClick(row, column, event) {
        if (row.name.id === undefined) {
          return
        }
        if (column.label === '考察项目') {
          this.columnA = row.name.id
          this.columnB = ''
        } else if (column.label === '全检用量') {
          this.columnB = row.name.id
          this.columnA = ''
        } else {
          this.columnA = ''
          this.columnB = ''
        }
        //row.boole = !row.boole
      },

      //删除行
      handlDele(index) {
        for (let i = 0; i < this.tableData.tableData.length; i++) {
          if (i === index) {
            this.tableData.tableData.splice(i, 1)
          }
        }
      },

      //hover
      cellStyle(data) {
        return 'cursor:pointer;'
      },

      //添加label
      handelAddRow(num, ind, index, label, unit, nums, ids) {

        this.idsss = ids
        this.openBoole = 1
        this.num = num
        this.index = index
        this.ind = ind
        let a = this.tableHead.findIndex(aa => aa.place_conditions.place_conditions_type
          .place_conditions_type_name === this.headerData[this.ind].prop
        )
        if (num === 2) {
          this.open = true
          this.title = '添加取样点'
        } else if (num === 3) {
          this.title = '编辑取样点'
          this.formOpen.label = label
          if (unit === '天') {
            this.formOpen.type = 1
          } else if (unit === '月') {
            this.formOpen.type = 2
          }
          this.open = true
          if (a !== -1) {
            this.formOpen.num = this.tableHead[a].sample_point.sample_point_info[
              index
              ].ceiling_sample_point_num
          }
        } else if (num === 4) {
          let prop_key = this.headerData[ind].children[index].prop
          for (let i = 0; i < this.tableData.tableData.length; i++) {
            if (i !== this.tableData.tableData.length - 1) {
              let obj = this.tableData.tableData[i]
              for (let key in obj) {
                if (prop_key === key) {
                  this.$delete(obj, key)
                }
              }
            }
          }
          this.headerData[ind].children.splice(index, 1)
          for (let i = 0; i < this.tableHead.length; i++) {
            let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
            if (this.headerData[this.ind].id === aaa) {
              this.tableHead[i].sample_point.sample_point_info.splice(index, 1)
            }
          }
        }
      },

      handelAdd() {
        var str,
          index,
          bbb = {},
          ccc = true
        if (this.formOpen.type === 1) {
          str = '天'
        } else if (this.formOpen.type === 2) {
          str = '月'
        }
        let data = {
          prop:
            this.headerData[this.ind].prop +
            '-' +
            this.formOpen.label +
            '-' +
            this.formOpen.type,
          label: this.formOpen.label,
          ids: this.headerData[this.ind].ids,
          unit: str,
          num: str === '天' ? 1 : 2,
          children: []
        }
        let b = {
          ceiling_sample_point_num: this.formOpen.num,
          sample_point_num: this.formOpen.label,
          sample_point_unit: this.formOpen.type
        }

        if (this.num === 2) {
          //右侧添加
          index = this.index + 1
          for (let i = 0; i < this.tableHead.length; i++) {
            let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
            if (this.headerData[this.ind].id === aaa) {
              bbb = {
                inspect_type_id: this.tableData.typeId, //考察类型id
                place_conditions_id: this.tableHead[i].place_conditions.id, //放置条件id
                sample_info_name: this.tableData.title, //样品名称
                stability_scheme_id: this.$route.query.id, //方案id
                sample_point_unit: this.formOpen.type, //取样时间单位
                ceiling_sample_point_num: this.formOpen.num, //取样上限时间
                sample_point_num: this.formOpen.label //取样时间数量
              }
              if (this.stability == 2) {
                pointList(bbb).then(res => {
                  if (res.code === 200) {
                    ccc = res.data
                  }
                })
              }
              if (!ccc) {
                this.$message.error('该取样点不能添加')
                this.cancel()
                return
              }
              this.headerData[this.ind].children.splice(index, 0, data)
              this.headerData[this.ind].children = [...new Set(this.headerData[this.ind].children)]
              this.tableData.tableData.forEach(item => {
                this.$set(
                  item,
                  this.headerData[this.ind].prop +
                  '-' +
                  this.formOpen.label +
                  '-' +
                  this.formOpen.type,
                  false
                )
              })
              this.tableHead[i].sample_point.sample_point_info.splice(index, 0, b)
            }
          }
        } else if (this.num === 3) {
          //编辑
          data = {
            prop: this.headerData[this.ind].children[this.index].prop,
            ids: this.headerData[this.ind].ids,
            label: this.formOpen.label,
            unit: str,
            num: str === '天' ? 1 : 2,
            children: []
          }
          let list1 = this.headerData[this.ind]
          this.$set(list1.children, this.index, data)
          this.$set(this.headerData, this.ind, list1)
          for (let i = 0; i < this.tableHead.length; i++) {
            let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
            if (this.headerData[this.ind].id === aaa) {
              this.$set(
                this.tableHead[i].sample_point.sample_point_info,
                this.index,
                b
              )
            }
          }
        }
        this.handlSort()
        this.handlHead()
      },

      //添加取样点排序
      handlSort() {
        for (let i = 0; i < this.headerData.length; i++) {
          let arr = this.headerData[i].children
          if (arr.length > 0) {
            arr.sort((a, b) => {
              if (a.num === b.num) {
                return a.label - b.label
              } else {
                return a.num - b.num
              }
            })
          }
        }
      },

      //原数组取样点排序
      handlHead() {
        for (let i = 0; i < this.tableHead.length; i++) {
          let arr = this.tableHead[i].sample_point.sample_point_info
          if (arr.length > 0) {
            arr.sort((a, b) => {
              if (a.sample_point_unit === b.sample_point_unit) {
                return a.sample_point_num - b.sample_point_num
              } else {
                return a.sample_point_unit - b.sample_point_unit
              }
            })
          }
        }
      },

      //取消
      cancel() {
        this.formOpen = {
          label: '',
          type: 1,
          num: 1,
          id: ''
        }
        this.open = false
        this.openBoole = undefined
      },

      //确定label
      submitForm() {
        this.$refs.formOpen.validate(valid => {
          if (valid) {
            if (this.openBoole == 1) {
              this.handelAdd()
            } else if (this.openBoole == 2) {
              this.handleAddTable()
            }

            this.cancel()
          } else {
            return false
          }
        })
      }
    }
    // methods: {
    //   //处理样品量
    //   totalTo: function(prop, label) {
    //     this.hanldChange()
    //     let a, b
    //     if (prop === 'num') {
    //       let num1 = 0,
    //         un_unit1 = '',
    //         unit1 = '',
    //         num_nuit1 = undefined,
    //         total1 = 0
    //
    //       for (let i = 0; i < this.tableData.tableData.length; i++) {
    //         if (this.tableData.tableData[i].num.packaging_nu !== undefined) {
    //           num1 += this.tableData.tableData[i].num.packaging_nu || 0
    //           un_unit1 = this.tableData.tableData[0].num.packaging_nu_unit || ''
    //           unit1 = this.tableData.tableData[0].num.packaging_unit || ''
    //           num_nuit1 = this.tableData.tableData[0].num.num_nuit
    //           if (num_nuit1 === 0 && un_unit1 === '') {
    //             a = `${num1} ${unit1}`
    //           } else {
    //             total1 = Math.ceil(num1 / num_nuit1) || 0
    //             a = `${num1} ${un_unit1} / ${total1} ${unit1}`
    //           }
    //         }
    //       }
    //       if (!this.tableData.combined.num) {
    //         this.tableData.combined.num = a
    //       }
    //       if (this.stability == 2) {
    //         return this.tableData.combined.num
    //       } else {
    //         this.tableData.combined.num = a
    //         return a
    //       }
    //     } else {
    //       let num = 0,
    //         un_unit = '',
    //         unit = '',
    //         num_nuit = undefined,
    //         total = 0
    //       let asd = 0
    //       for (let i = 0; i < this.tableData.tableData.length; i++) {
    //         if (this.tableData.tableData[i][prop]) {
    //           asd++
    //           num += this.tableData.tableData[i].num.packaging_nu || 0
    //         }
    //         un_unit = this.tableData.tableData[0].num.packaging_nu_unit || ''
    //         unit = this.tableData.tableData[0].num.packaging_unit || ''
    //         num_nuit = this.tableData.tableData[0].num.num_nuit
    //         let ssa = asd ? 1 : 0
    //         total = Math.ceil(num / num_nuit) || ssa
    //         if (num_nuit === 0 && un_unit === '') {
    //           b = `${num} ${unit}`
    //         } else {
    //           b = `${num} ${un_unit} / ${total} ${unit}`
    //         }
    //       }
    //       if (!this.tableData.combined[prop]) {
    //         this.tableData.combined[prop] = b
    //       }
    //       if (!this.ssss[label]) {
    //         this.ssss[label] = []
    //       }
    //       if (total == Infinity) {
    //         total = num
    //       }
    //       let data = {
    //         val: total,
    //         prop: prop,
    //         unit: unit
    //       }
    //       let index = this.ssss[label].findIndex(a => a.prop == prop)
    //       if (index != -1) {
    //         this.ssss[label][index] = data
    //       } else {
    //         this.ssss[label].push(data)
    //       }
    //       if (this.stability == 2) {
    //         let cc
    //         if (this.tableData.combined[prop]) {
    //           cc = this.tableData.combined[prop]
    //         } else {
    //           cc = `1 ${un_unit} /1 ${unit}`
    //         }
    //         return cc
    //       } else {
    //         this.tableData.combined[prop] = b
    //         return b
    //       }
    //     }
    //
    //   },
    //
    //   //求和
    //   sumNum() {
    //     let num = 0
    //     for (let i = 0; i < this.totalof.length; i++) {
    //       num += this.totalof[i].value * this.totalof[i].arrList.length
    //     }
    //     return num
    //   },
    //
    //   //获取项目下拉
    //   handlDown() {
    //     downListProject().then(res => {
    //       if (res.code === 200) {
    //         this.projectData = res.data || []
    //       }
    //     })
    //   },
    //
    //   //处理表头
    //   hanldTable(arrData) {
    //     this.tableData.headList = []
    //     let aaa = [],
    //       data = {}
    //     for (let i = 0; i < arrData.length; i++) {
    //       if (!data[arrData[i].place_conditions.place_conditions_type.id]) {
    //         data[arrData[i].place_conditions.place_conditions_type.id] = [
    //           arrData[i]
    //         ]
    //       } else {
    //         data[arrData[i].place_conditions.place_conditions_type.id].push(
    //           arrData[i]
    //         )
    //       }
    //     }
    //     for (let key in data) {
    //       let str = '',
    //         ids = ''
    //       for (let j = 0; j < data[key].length; j++) {
    //         let dataVal = data[key][j]
    //         str +=
    //           data[key][j].place_conditions.place_conditions_type
    //             .place_conditions_type_name +
    //           '(' +
    //           data[key][j].place_conditions.place_conditions_name +
    //           ')'
    //         ids +=
    //           data[key][j].place_conditions.place_conditions_type.id + '&?' +
    //           data[key][j].place_conditions.id
    //         if (j == data[key].length - 1) {
    //           let children = []
    //           for (
    //             let k = 0;
    //             k < dataVal.sample_point.sample_point_info.length;
    //             k++
    //           ) {
    //             let infoData = dataVal.sample_point.sample_point_info[k]
    //             let val = {
    //               label: infoData.sample_point_num,
    //               unit: infoData.sample_point_unit === 1 ? '天' : '月',
    //               prop:
    //                 dataVal.place_conditions.place_conditions_type
    //                   .place_conditions_type_name +
    //                 '' +
    //                 '-' +
    //                 infoData.sample_point_num +
    //                 '-' +
    //                 infoData.sample_point_unit,
    //               num: infoData.sample_point_unit,
    //               children: []
    //             }
    //             children.push(val)
    //           }
    //           this.tableData.headList.push(dataVal.place_conditions.place_conditions_type
    //             .place_conditions_type_name)
    //           children = [...new Set(children)]
    //           aaa.push({
    //             label: str,
    //             ids: ids,
    //             prop:
    //               data[key][0].place_conditions.place_conditions_type
    //                 .place_conditions_type_name + '',
    //             id: key,
    //             children: children
    //           })
    //         } else {
    //           str = str + '、'
    //           ids = ids + '、'
    //         }
    //       }
    //     }
    //     aaa = [...new Set(aaa)]
    //     return aaa
    //   },
    //
    //   //添加取样点排序
    //   handlSort() {
    //     for (let i = 0; i < this.headerData.length; i++) {
    //       let arr = this.headerData[i].children
    //       if (arr.length > 0) {
    //         arr.sort((a, b) => {
    //           if (a.num === b.num) {
    //             return a.label - b.label
    //           } else {
    //             return a.num - b.num
    //           }
    //         })
    //       }
    //     }
    //   },
    //
    //   //原数组取样点排序
    //   handlHead() {
    //     for (let i = 0; i < this.tableHead.length; i++) {
    //       let arr = this.tableHead[i].sample_point.sample_point_info
    //       if (arr.length > 0) {
    //         arr.sort((a, b) => {
    //           if (a.sample_point_unit === b.sample_point_unit) {
    //             return a.sample_point_num - b.sample_point_num
    //           } else {
    //             return a.sample_point_unit - b.sample_point_unit
    //           }
    //         })
    //       }
    //     }
    //   },
    //
    //   //总计input
    //   handlTotal() {
    //     let list = []
    //     if (this.tableData.total.a !== undefined) {
    //       let index = this.tableData.total.a.findIndex(
    //         b => b.sample.id === this.tableList.id
    //       )
    //       if (index !== -1) {
    //         this.tableData.total.a[index].sample = this.tableList
    //         this.tableData.total.a[index].arrList.forEach(item => {
    //           item.sample = this.tableList
    //         })
    //       }
    //       list = this.tableData.total.a
    //       // this.totalof = this.tableData.total.a;
    //     } else {
    //       this.totalof = []
    //     }
    //
    //     for (let i = 0; i < this.headerData.length; i++) {
    //       if (this.headerData[i].children.length > 0) {
    //         let value = 0
    //         let obj = null
    //         let arrList = []
    //         let labelArr = this.headerData[i].label.split('、')
    //         let idArr = this.headerData[i].ids.split('、')
    //
    //         let aa = list.findIndex(a => a.ids == this.headerData[i].ids)
    //         if (aa != -1) {
    //           arrList = list[aa].arrList
    //           value = list[aa].value
    //         } else {
    //           for (let i = 0; i < labelArr.length; i++) {
    //             obj = {
    //               name: labelArr[i],
    //               id: idArr[i],
    //               sample: this.tableList,
    //               value: 0
    //             }
    //             arrList.push(obj)
    //           }
    //         }
    //
    //         this.totalof.push({
    //           [this.headerData[i].ids]: this.headerData[i].ids.split('、'),
    //           value: value,
    //           unit: '',
    //           arrList: arrList,
    //           label: this.headerData[i].label,
    //           ids: this.headerData[i].ids,
    //           sample: this.tableList
    //         })
    //       }
    //     }
    //     this.tableData.total = { a: this.totalof }
    //   },
    //
    //   //处理表的prop数据
    //   hanldList() {
    //     let arr = [],
    //       data = {}
    //     for (let i = 0; i < this.headerData.length; i++) {
    //       data[this.headerData[i].prop] = ''
    //       if (this.headerData[i].children.length > 0) {
    //         for (let j = 0; j < this.headerData[i].children.length; j++) {
    //           data[this.headerData[i].children[j].prop] = false
    //         }
    //       }
    //     }
    //     let inspect_projects = this.tableList.sample_type_info.inspect_projects
    //     for (let k = 0; k < inspect_projects.length; k++) {
    //       let a = {
    //         id: inspect_projects[k].id,
    //         inspect_project_name: inspect_projects[k].inspect_project_name
    //       }
    //       let b = {
    //         packaging_nu: this.tableList.packaging_nu,
    //         num_nuit: this.tableList.packaging_nu,
    //         packaging_nu_unit: this.tableList.packaging_nu_unit,
    //         packaging_unit: this.tableList.packaging_unit
    //       }
    //       data.name = a
    //       data.num = b
    //       data.boole = true
    //       arr.push({ ...data })
    //     }
    //     if (this.tableData.tableData.length === 0) {
    //       this.tableData.tableData = arr
    //       this.tableData.tableData.push(this.aaa)
    //     } else {
    //     }
    //   },
    //
    //   //
    //   hanldChange(val) {
    //
    //     setTimeout(_ => {
    //       for (let j = 0; j < this.totalof.length; j++) {
    //         this.totalof[j].value = 0
    //         if (this.ssss[this.totalof[j].label]) {
    //           let num = 0
    //           for (let k = 0; k < this.ssss[this.totalof[j].label].length; k++) {
    //             this.totalof[j].value += this.ssss[this.totalof[j].label][k].val
    //             this.totalof[j].unit = this.ssss[this.totalof[j].label][k].unit
    //             for (let i = 0; i < this.totalof[j].arrList.length; i++) {
    //               this.totalof[j].arrList[i].value = this.totalof[j].value
    //             }
    //           }
    //           this.tableData.total = { a: this.totalof }
    //         }
    //       }
    //     }, 100)
    //   },
    //
    //   //添加项目
    //   addTable() {
    //     this.openBoole = 2
    //     this.open = true
    //     this.title = '选择项目'
    //   },
    //
    //   handleAddTable() {
    //     let data = {},
    //       name = '',
    //       index = 0
    //     data = this.tableData.tableData[0]
    //     index = this.projectData.findIndex(a => a.id == this.formOpen.id)
    //     if (index !== -1) {
    //       name = this.projectData[index].inspect_project_name
    //     }
    //     data.name.id = this.formOpen.id
    //     data.name.inspect_project_name = name
    //     //this.tableData.tableData.push(data)
    //     this.tableData.tableData.splice(
    //       this.tableData.tableData.length - 1,
    //       0,
    //       data
    //     )
    //   },
    //
    //   //单机行
    //   aloneClick(row, column, event) {
    //     if (
    //       column.label === '考察项目' ||
    //       column.label === '全检用量' ||
    //       row.name.inspect_project_name === '样品量'
    //     ) {
    //       return
    //     }
    //     row.boole = !row.boole
    //   },
    //
    //   //hover
    //   cellStyle(data) {
    //     return 'cursor:pointer;'
    //   },
    //
    //   //添加label
    //   handelAddRow(num, ind, index, label, unit) {
    //     this.openBoole = 1
    //     this.num = num
    //     this.index = index
    //     this.ind = ind
    //     this.title = '添加取样点'
    //     let a = this.tableHead.findIndex(
    //       a =>
    //         a.place_conditions.place_conditions_type
    //           .place_conditions_type_name === this.headerData[this.ind].prop
    //     )
    //     if (num === 1 || num === 2) {
    //       this.open = true
    //     } else if (num === 3) {
    //       this.formOpen.label = label
    //       if (unit === '天') {
    //         this.formOpen.type = 1
    //       } else if (unit === '月') {
    //         this.formOpen.type = 2
    //       }
    //       this.open = true
    //       if (a !== -1) {
    //         this.formOpen.num = this.tableHead[a].sample_point.sample_point_info[
    //           index
    //           ].ceiling_sample_point_num
    //       }
    //     } else if (num === 4) {
    //       this.headerData[ind].children.splice(index, 1)
    //       for (let i = 0; i < this.tableHead.length; i++) {
    //         let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
    //         if (this.headerData[this.ind].id === aaa) {
    //           this.tableHead[i].sample_point.sample_point_info.splice(index, 1)
    //         }
    //       }
    //     }
    //   },
    //
    //   handelAdd() {
    //     var str, index
    //     if (this.formOpen.type === 1) {
    //       str = '天'
    //     } else if (this.formOpen.type === 2) {
    //       str = '月'
    //     }
    //     let data = {
    //       prop:
    //         this.headerData[this.ind].prop +
    //         '-' +
    //         this.formOpen.label +
    //         '-' +
    //         this.formOpen.type,
    //       label: this.formOpen.label,
    //       unit: str,
    //       children: []
    //     }
    //     let b = {
    //       ceiling_sample_point_num: this.formOpen.num,
    //       sample_point_num: this.formOpen.label,
    //       sample_point_unit: this.formOpen.type
    //     }
    //
    //     if (this.num === 1) {
    //       //左侧添加
    //       index = this.index
    //       this.headerData[this.ind].children.splice(index, 0, data)
    //       this.tableData.tableData.forEach(item => {
    //         this.$set(
    //           item,
    //           this.headerData[this.ind].prop +
    //           '-' +
    //           this.formOpen.label +
    //           '-' +
    //           this.formOpen.type,
    //           ''
    //         )
    //       })
    //       for (let i = 0; i < this.tableHead.length; i++) {
    //         let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
    //         if (this.headerData[this.ind].id === aaa) {
    //           this.tableHead[i].sample_point.sample_point_info.splice(
    //             index,
    //             0,
    //             b
    //           )
    //         }
    //       }
    //     } else if (this.num === 2) {
    //       //右侧添加
    //       index = this.index + 1
    //       this.headerData[this.ind].children.splice(index, 0, data)
    //       this.tableData.tableData.forEach(item => {
    //         this.$set(
    //           item,
    //           this.headerData[this.ind].prop +
    //           '-' +
    //           this.formOpen.label +
    //           '-' +
    //           this.formOpen.type,
    //           ''
    //         )
    //       })
    //       for (let i = 0; i < this.tableHead.length; i++) {
    //         let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
    //         if (this.headerData[this.ind].id === aaa) {
    //           this.tableHead[i].sample_point.sample_point_info.splice(
    //             index,
    //             0,
    //             b
    //           )
    //         }
    //       }
    //     } else if (this.num === 3) {
    //       //编辑
    //       data = {
    //         prop: this.headerData[this.ind].children[this.index].prop,
    //         label: this.formOpen.label,
    //         unit: str,
    //         children: []
    //       }
    //       let list1 = this.headerData[this.ind]
    //       this.$set(list1.children, this.index, data)
    //       this.$set(this.headerData, this.ind, list1)
    //       for (let i = 0; i < this.tableHead.length; i++) {
    //         let aaa = this.tableHead[i].place_conditions.place_conditions_type.id
    //         if (this.headerData[this.ind].id === aaa) {
    //           this.$set(
    //             this.tableHead[i].sample_point.sample_point_info,
    //             this.index,
    //             b
    //           )
    //         }
    //       }
    //     }
    //   },
    //
    //   //取消
    //   cancel() {
    //     this.formOpen = {
    //       label: '',
    //       type: 1,
    //       num: 1,
    //       id: ''
    //     }
    //     this.open = false
    //     this.openBoole = undefined
    //   },
    //
    //   //确定label
    //   submitForm() {
    //     this.$refs.formOpen.validate(valid => {
    //       if (valid) {
    //         if (this.openBoole == 1) {
    //           this.handelAdd()
    //         } else if (this.openBoole == 2) {
    //           this.handleAddTable()
    //         }
    //
    //         this.cancel()
    //       } else {
    //         return false
    //       }
    //     })
    //   }
    // }
  }
</script>
<style scoped>
  /* @import url(); 引入css类 */
  ::v-deep .table1 tr td {
    padding: 0 !important;
    height: 48px !important;
    overflow: visible !important;
    line-height: 48px;
  }

  ::v-deep .table1 tr td .cell {
    height: 30px !important;
    overflow: visible !important;
    line-height: 30px;
  }

  ::v-deep .item_form {
    overflow: hidden;
  }

  .zong {
    width: 100%;
    height: 48px;
    border: 1px solid #ebeef5;
    border-top: none;
    display: flex;
    align-items: center;
    box-sizing: border-box;
  }

  .left {
    width: 200px;
    height: 48px;
    border-right: 1px solid #ebeef5;
    box-sizing: border-box;
    line-height: 48px;
    padding-left: 20px;
    font-size: 16px;
    font-size: 14px;
    text-align: center;
  }

  .rigth {
    width: calc(100% - 200px);
  }

  ::v-deep .el-input-group__prepend {
    background-color: #ffffff;
  }

  ::v-deep .el-input-group__append {
    background-color: #ffffff;
  }

  ::v-deep .form-item .el-form-item__content {
    display: flex;
    justify-content: flex-start;
    /* width: 400px; */
  }

  ::v-deep .form-item {
    margin-bottom: 0px !important;
    padding: 0 10px;
  }
</style>
